@extends('Admin.layouts.index');

@section('content')	
<script src="{{url('admin/js/jquery.js')}}"></script>

<div class="box span12">
	<div class="box-header" data-original-title>
		<h2><i class="halflings-icon white edit"></i><span class="break"></span>添加表格</h2>
		<div class="box-icon">
			<a href="#" class="btn-setting"><i class="halflings-icon white wrench"></i></a>
			<a href="#" class="btn-minimize"><i class="halflings-icon white chevron-up"></i></a>
			<a href="#" class="btn-close"><i class="halflings-icon white remove"></i></a>
		</div>
	</div>
	<div class="box-content">
		<form class="form-horizontal" action="/admin/users" method="get" id="art_form">
		{{ csrf_field() }}
		  <fieldset>
			<div class="control-group">
			  <label class="control-label" for="date01">链接名称</label>
			  <div class="controls">
				<input type="text" name="title" value="">
			  </div>
			</div>
			<div class="control-group">
			  <label class="control-label" for="date01">链接地址</label>
			  <div class="controls">
				<input type="text" name="url" value="">
			  </div>
			</div>
			<div class="control-group">
			  <label class="control-label" for="date01">图标</label>
			  <div class="controls">
				<input type="file" name="image" value="" id="file_upload">
					<script>
						 $(function(){
							$('#file_upload').change(function(){
								uploadImage();
							});

						 });
					    function uploadImage() {
    					//  判断是否有选择上传文件
        				var imgPath = $("#file_upload").val();
        				if (imgPath == "") {
            				alert("请选择上传图片！");
            				return;
        				}
        				//判断上传文件的后缀名
        				var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
        				if (strExtension != 'jpg' && strExtension != 'gif'&& strExtension != 'png' && strExtension != 'bmp') {
            					alert("请选择图片文件");
            					return;
        					}
        				var formData = new FormData($('#art_form')[0]);
        				$.ajax({
           	 				type: "POST",
            				url: "/admin/upload",
            				data: formData,
            				contentType: false,
            				processData: false,
            				success: function(data) {
                				$('#img1').attr('src','/'+data);
                				$('#art_thumb').val(data);
            				},
            				error: function(XMLHttpRequest, textStatus, errorThrown) {
                				alert("上传失败，请检查网络后重试");
            				}
        				});
    				}
					</script>
			  </div>
			</div>
		
			<div class="form-actions">
			  <button type="submit" class="btn btn-primary">添加</button>
			  <button type="reset" class="btn">重置</button>
			</div>
		  </fieldset>
		</form>   

	</div>
</div><!--/span-->

@endsection